<template>
	<!-- 添加或修改年度考核记录对话框 -->
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="560px" append-to-body>
		<el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="保密人员" prop="userId">
						<person-select v-model="formData.userId" :list="checkedUsers" :disabled="isDisabled"></person-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="考核等次" prop="result">
						<el-select v-model="formData.result" placeholder="选择考核等次">
							<el-option v-for="(item, index) in dict.type.sp_examine_level" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="考核年份" prop="year">
						<el-date-picker v-model="checkYearData" v-bind="dateConfig"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="是否校先进个人" prop="isAdvanced" label-width="120px">
						<el-radio-group v-model="formData.isAdvanced" :aria-hidden="false">
							<el-radio v-for="(item, index) in dict.type.sys_yes_no" :key="index" :label="item.value">{{ item.label }}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button type="primary" @click="handleSubmitData()">确定</el-button>
			<el-button @click="visible = false">取消</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '../common/formMixins';
import { getYear, addYear, updateYear } from '@/api/personnal/examine';
export default {
	mixins: [formMixins],
	dicts: ['sp_examine_level', 'sys_yes_no'],
	data() {
		return {
			formName: '年度考核记录',
			formRules: {
				userId: { required: true, message: '请选择保密人员', trigger: 'change' },
				result: { required: true, message: '请选择考核等次', trigger: 'change' },
				year: { required: true, message: '请选择考核年份', trigger: 'change' },
				isAdvanced: { required: true, message: '请选择是否先进个人', trigger: 'change' }
			},
			dateConfig: {
				type: 'year',
				editable: false,
				valueFormat: 'yyyy',
				style: { width: '100%' },
				placeholder: '请选择考核年份'
			}
		};
	},
	computed: {
		detailFunction() {
			return eval(getYear);
		},
		callFunction() {
			return eval(this.addOrEdit ? addYear : updateYear);
		},
		checkYearData: {
			get() {
				let year = this.formData.year;
				return !year ? '' : String(this.formData.year);
			},
			set(value) {
				this.$set(this.formData, 'year', Number(value));
			}
		}
	},
	watch: {
		userDetail(data) {
			this.$set(this.formData, 'userName', data.name);
		}
	},
	methods: {
		//格式化请求参数
		formatRequestParams() {
			let params = { ...this.formData };
			return params;
		}
	}
};
</script>

<style scoped></style>
